package com.yundasys.lab02springbootstudy.config;

import com.yundasys.lab02springbootstudy.annotation.LinuxCondition;
import com.yundasys.lab02springbootstudy.annotation.WindowsCondition;
import com.yundasys.lab02springbootstudy.bean.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @author jiangta
 * @version 1.0
 * @date 2021/1/12 2:35 下午
 */
@Configuration
public class BeanConfig {


    //只有一个类时，大括号可以省略
    //如果WindowsCondition的实现方法返回true，则注入这个bean
    @Conditional({WindowsCondition.class})
    @Bean(name = "bill")
    public Person person1() {
        return new Person("Bill Gates",62);
    }

    //如果LinuxCondition的实现方法返回true，则注入这个bean
    @Conditional({LinuxCondition.class})
    @Bean("linus")
    public Person person2() {
        return new Person("Linus",48);
    }
}
